﻿@using BootstrapBlazor.Components
@using TrackSystem.Entities.Extensions

<div class="row">
    <div class="col-4">名称</div>
    <div class="col-8"><BootstrapInput @bind-Value="Sensor.Name" /></div>
</div>
<div class="row">
    <div class="col-4">描述</div>
    <div class="col-8"><BootstrapInput @bind-Value="Sensor.Description" /></div>
</div>
<div class="row">
    <div class="col-4">端口</div>
    <div class="col-8">
        <Dropdown @bind-Value=Sensor.channelID Items="lstStation" Color="Color.Info" OnSelectedItemChanged="@OnPtlChanged" />
    </div>
</div>

<Divider class="mt-3 mb-3" />

@if ( Chn != null )
{
    @if (!_ptlParams.ExclusiveMode)
    {
        <div class="row">
            <div class="col-6" >站地址</div>
            <div class="col-6"><BootstrapInputNumber @bind-Value=Sensor.Station Color="Color.Info" PlaceHolder="站地址" /></div>
        </div>
    }

    @if (_ptlParams.StartAdr_RO == -1)
    {
        <div class="row">
            <div class="col-5">RO起始</div>
            <div class="col-2"></div>
            <div class="col-5">RO长度</div>
        </div>
        <div class="row">
            <div class="col-5"><BootstrapInputNumber @bind-Value=Sensor.RO_Address Color="Color.Info" /></div>
            <div class="col-2"></div>
            <div class="col-5"><BootstrapInputNumber @bind-Value=Sensor.RO_Length Color="Color.Info" /></div>
        </div>
    }

    if (_ptlParams.StartAdr_RW == -1)
    {
        <div class="row">
            <div class="col-5">RW起始</div>
            <div class="col-2"></div>
            <div class="col-5">RW长度</div>
        </div>
        <div class="row">
            <div class="col-5"><BootstrapInputNumber @bind-Value=Sensor.RW_Address Color="Color.Info" /></div>
            <div class="col-2"></div>
            <div class="col-5"><BootstrapInputNumber @bind-Value=Sensor.RW_Length Color="Color.Info" /></div>
        </div>
    }
}

<Divider class="mt-3 mb-3" />

<div class="d-flex">
    @if (Chn != null)
    {
        <div class="ps-2">

            <div>@Chn.Name (@Chn.PortCategory.ToString() )</div>
            @if (Chn.PortCategory == PortCategory.SRIAL)
            {
                <div class="user-demo-address">
                    @($"串口: {Chn.COMn},{Chn.Baudrate},{Chn.SerialParams}")
                </div>
            }
            else
            {
                <div class="user-demo-address">
                    @($"远程: {Chn.Ip}:{Chn.Port}")
                </div>
            }

            @if (Chn.PortCategory == PortCategory.UDP)
            {
                <div class="user-demo-address">
                    @($"本地: {Chn.localIp}:{Chn.localPort}")
                </div>
            }
            else
            {
                <div class="user-demo-address">
                    <br />
                </div>
            }
            <p>通信协议: @Chn.Protocol.ToString()</p>
        </div>
    }
</div>


